package com.wgj.android.zfp;

import android.util.Log;

import com.google.gson.Gson;
import com.jiaai.xui.XUI;
import com.wgj.android.base.WGJApplication;
import com.wgj.android.http.weixin.WXHttp;
import com.wgj.android.http.weixin.WeiXinCacheUtil;
import com.wgj.android.http.weixin.event.CleanEvent;
import com.wgj.android.http.weixin.model.BaseRequest;
import com.wgj.android.http.weixin.model.SetZombieDemoBody;

import org.greenrobot.eventbus.EventBus;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/11/29.
 */

public class ModifyTask implements Runnable {
    private static String TAG="ModifyTask";
    private Gson gson = new Gson();

    private String toUserName;
    private String toNickName;
    private BaseRequest baseRequest;

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getToNickName() {
        return toNickName;
    }

    public void setToNickName(String toNickName) {
        this.toNickName = toNickName;
    }

    public BaseRequest getBaseRequest() {
        return baseRequest;
    }

    public void setBaseRequest(BaseRequest baseRequest) {
        this.baseRequest = baseRequest;
    }

    public ModifyTask(String toUserName, String toNickName, BaseRequest baseRequest) {
        this.toUserName = toUserName;
        this.toNickName = toNickName;
        this.baseRequest = baseRequest;
    }

    @Override
    public void run() {
        modifyNickName();
    }

    private void modifyNickName() {

        SetZombieDemoBody setZombieDemoBody = new SetZombieDemoBody();
        setZombieDemoBody.setBaseRequest(baseRequest);
        setZombieDemoBody.setUserName(toUserName);
        setZombieDemoBody.setRemarkName("A00僵尸粉-".concat(toNickName));
        String url = "http://" + WeiXinCacheUtil.getInfo().getBaseUrl() + "/cgi-bin/mmwebwx-bin/webwxoplog";
        try {
            String res = WXHttp.obtain().syncPost(url, new Gson().toJson(setZombieDemoBody));
            if (res.contains("1")){
                //post清除失败
                Log.i(TAG, "备注失败: ".concat(toNickName).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));//todo delete
                EventBus.getDefault().post(new CleanEvent(toNickName, CleanEvent.type.FAILED));
            }else {
                //post清除成功
                Log.i(TAG, "成功备注: ".concat(toNickName).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));//todo delete
                EventBus.getDefault().post(new CleanEvent(toNickName, CleanEvent.type.SUCCESS));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
